package org.walkerljl.commons.dts;

import java.io.Serializable;
import java.util.List;

/**
 * DTS Result
 *
 * @author lijunlin
 */
public class DtsResult implements Serializable {

    private static final long serialVersionUID = 1L;
    private boolean result;
    private String message;
    private List<DtsParam> completedParams;
    private Throwable throwable;

    /**
     * 默认构造函数
     */
    public DtsResult() {
    }

    public static DtsResult success() {
        return new DtsResult(true, null, null, null);
    }

    public static DtsResult success(String message) {
        return new DtsResult(true, message, null, null);
    }

    public static DtsResult failure(String message) {
        return new DtsResult(false, message, null, null);
    }

    public static DtsResult failure(String message, Throwable throwable) {
        return new DtsResult(false, message, null, throwable);
    }

    public static DtsResult failure(String message, List<DtsParam> completedParams) {
        return new DtsResult(false, message, completedParams, null);
    }

    public static DtsResult failure(String message, List<DtsParam> completedParams, Throwable throwable) {
        return new DtsResult(false, message, completedParams, throwable);
    }

    private DtsResult(boolean result, String message, List<DtsParam> completedParams, Throwable throwable) {
        this.result = result;
        this.message = message;
        this.completedParams = completedParams;
        this.throwable = throwable;
    }

    public boolean isSuccess() {
        return result;
    }

    public boolean isFailure() {
        return !isSuccess();
    }

    public boolean isResult() {
        return result;
    }

    public void setResult(boolean result) {
        this.result = result;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public List<DtsParam> getCompletedParams() {
        return completedParams;
    }

    public void setCompletedParams(List<DtsParam> completedParams) {
        this.completedParams = completedParams;
    }

    public Throwable getThrowable() {
        return throwable;
    }

    public void setThrowable(Throwable throwable) {
        this.throwable = throwable;
    }

    @Override
    public String toString() {
        return "DtsResult{" +
                "result=" + result +
                ", message='" + message + '\'' +
                ", completedParams=" + completedParams +
                ", throwable=" + throwable +
                '}';
    }
}
